package edu.vt.ece.rt.benchmark.intruder;

import java.util.Vector;


public class Detector {

    Dictionary dictionaryPtr;
    Vector<Preprocessor> PreprocessorVectorPtr;

    public Detector() {
        dictionaryPtr = new Dictionary();
        PreprocessorVectorPtr = new Vector<Preprocessor>();

    }
	
    /* =============================================================================
     * detector_addPreprocessor
     * =============================================================================
     */
    void
    detector_addPreprocessor (Detector detectorPtr, Preprocessor p)
    {
        detectorPtr.PreprocessorVectorPtr.add(p);
//        assert(status);
    }


    /* =============================================================================
     * detector_process
     * =============================================================================
     */
    static Error.error
    detector_process (Detector detectorPtr, String str)
    {
        /*
         * Apply Preprocessors
         */

//    	str = Preprocessor.Preprocessor_convertURNHex(str);
    	str = Preprocessor.Preprocessor_toLower(str);

        /*
         * Check against signatures of known attacks
         */

        String signature = Dictionary.dictionary_match(detectorPtr.dictionaryPtr, str);
        if (signature != null) {
            return Error.error.ERROR_SIGNATURE;
        }

        return Error.error.ERROR_NONE;
    }


    static String str1= "test";
    static String str2 = "abouts";
    static String str3 = "aBoUt";
    static String str4 = "%41Bout";


    public static void main (String[] args) 
    {
        System.out.println("Starting...");

        Detector detectorPtr = new Detector();

//        detector_addPreprocessor(detectorPtr, &Preprocessor_convertURNHex);
//        detector_addPreprocessor(detectorPtr, &Preprocessor_toLower);

        assert(detector_process(detectorPtr, str1) == Error.error.ERROR_NONE);
        assert(detector_process(detectorPtr, str2) == Error.error.ERROR_SIGNATURE);
        assert(detector_process(detectorPtr, str3) == Error.error.ERROR_SIGNATURE);
        assert(detector_process(detectorPtr, str4) == Error.error.ERROR_SIGNATURE);


        System.out.println("All tests passed.");

    }

}
